libname aetna 'C:\HSPH\manuscripts\Aetna\Dimension';
options NOFMTERR;

data wellbeing_p;
set aetna.new;

/*delete participants with missing data on 2019 work outcomes*/
if nmiss (of distracted2019 jobsatis2019)>0 then delete; 

*Recode work distraction outcome (and prior value), taking the mid-point of the response category;
if distracted2019=1 then distracted2019_r=0;
else if distracted2019=2 then distracted2019_r=0.075;
else if distracted2019=3 then distracted2019_r=0.175;
else if distracted2019=4 then distracted2019_r=0.375;
else if distracted2019=5 then distracted2019_r=0.75;
label distracted2019_r='work distraction in 2019';

if distracted2018=1 then distracted2018_r=0;
else if distracted2018=2 then distracted2018_r=0.075;
else if distracted2018=3 then distracted2018_r=0.175;
else if distracted2018=4 then distracted2018_r=0.375;
else if distracted2018=5 then distracted2018_r=0.75;
label distracted2018_r='baseline work distraction in 2018';

/*recode covariates*/
if age_cat2018=1 then age_cat2018c=1; *<=30;
else if age_cat2018 in (2, 3) then age_cat2018c=2; *31-50;
else if age_cat2018=4 then age_cat2018c=3; *>50;

if mart_status2018 in (2, 6) then mart_status2018c=1; *married, partnership;
else if mart_status2018 in (1, 3, 4, 5) then mart_status2018c=0; *unmarried;

if educ2018=2 then educ2018c=1; *HS;
else if educ2018=3 then educ2018c=2; *some colleage;
else if educ2018 in (4, 5) then educ2018c=3; *college;
else if educ2018=6 then educ2018c=4; *graduate school;

if home2018=1 then home2018c=1; *yes;
else if home2018=2 then home2018c=0; *no;

if n_children2018>0 then n_children2018c=1;
else if n_children2018=0 then n_children2018c=0;

if n_elders2018>0 then elders2018c=1;
else if n_elders2018=0 then elders2018c=0;

if rel_attend2018 in (1, 2, 3) then rel_attend2018_r=2; *>=1x/wk;
else if rel_attend2018=7 then rel_attend2018_r=0; *never;
else if rel_attend2018 in (4, 5, 6) then rel_attend2018_r=1; *<1x/wk;

if community2018 in (1, 2, 3) then community2018_r=2;*>=1x/wk;
else if community2018=7 then community2018_r=0;*never;
else if community2018 in (4, 5, 6) then community2018_r=1;*<1x/wk;

if volunt2018 in (1, 2, 3) then volunt2018_r=2;*>=1x/wk;
else if volunt2018=7 then volunt2018_r=0;*never;
else if volunt2018 in (4, 5, 6) then volunt2018_r=1;*<1x/wk;

if spirituality2018 in (1, 2, 3) then spirituality2018_r=2;*>=1x/wk;
else if spirituality2018=7 then spirituality2018_r=0;*never;
else if spirituality2018 in (4, 5, 6) then spirituality2018_r=1;*<1x/wk;

if work_hours2018=1 then work_hours2018c=1;*<8h;
else if work_hours2018=6 then work_hours2018c=2;*8h;
else if work_hours2018=2 then work_hours2018c=3;*9-10h;
else if work_hours2018 in (3, 4, 5) then work_hours2018c=4;*>10h;

if work_home2018=0 then work_home2018d=0;
else if work_home2018 in (1, 2, 3, 4) then work_home2018d=1; 
else if work_home2018=5 then work_home2018d=2;  *0, 1-4 days, 5 days;

if vote2018=3 then vote2018=.;
else if vote2018=4 then vote2018=3;

/*create 2018 flourishing scores of other dimensions, excluding one domain at a time*/
WELL_BEING_eH2018_em= (phys_hlth_dim_H2018+financ_WB2_H2018+char_str_H2018+social_WB_H2018+purpose_dim2_H2018)/5;
WELL_BEING_eH2018_ph= (emot_hlth_dim2_H2018+financ_WB2_H2018+char_str_H2018+social_WB_H2018+purpose_dim2_H2018)/5;
WELL_BEING_eH2018_sc= (emot_hlth_dim2_H2018+phys_hlth_dim_H2018+financ_WB2_H2018+char_str_H2018+purpose_dim2_H2018)/5; 
WELL_BEING_eH2018_ch= (emot_hlth_dim2_H2018+phys_hlth_dim_H2018+financ_WB2_H2018+social_WB_H2018+purpose_dim2_H2018)/5; 
WELL_BEING_eH2018_fn= (emot_hlth_dim2_H2018+phys_hlth_dim_H2018+char_str_H2018+social_WB_H2018+purpose_dim2_H2018)/5;  
WELL_BEING_eH2018_ps= (emot_hlth_dim2_H2018+phys_hlth_dim_H2018+char_str_H2018+social_WB_H2018+financ_WB2_H2018)/5;  

label WELL_BEING_eH2018_em='baseline flourishing_exclude emotional wellbeing';
label WELL_BEING_eH2018_ph='baseline flourishing_exclude physical health';
label WELL_BEING_eH2018_sc='baseline flourishing_exclude social connectedness';
label WELL_BEING_eH2018_ch='baseline flourishing_exclude character stregnth';
label WELL_BEING_eH2018_fn='baseline flourishing_exclude financial security';
label WELL_BEING_eH2018_ps='baseline flourishing_exclude purpose in life';

proc format;
value age_cat2018c
      1= '30 or below'
	  2= '31-50'
      3= 'above 50';

value gender2018c
      1= 'female'
	  2= 'male';

value race22018c 
      0= 'white (not Hispanic)'
	  1= 'Black/African-American'
	  2= 'Other';

value mart_status2018c
      0= 'Unmarried'
      1= 'Married or in partnership';

value educ2018c
      1= 'high school diploma or eqivalent'
	  2= 'Some college but no degree'
	  3= 'College degree'
      4= 'Graduate school';

value home2018c
      0= 'no'
	  1= 'yes';

value n_children2018c
      0= 'no children'
      1= 'have children';	  

value elders2018c
      0= 'no'
      1= 'yes';	

value work_hours2018c 
      1= '<8h'
      2= '8h'
	  3= '9-10h'
      4= '>10h';

value flsa_type2018c
      1='exempt'
	  2='non-exempt';

value work_home2018d
      0= '0 days/week'
	  1= '1-4 days/week'
	  2= '5 days/week';

value rel_attend2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';    

value community2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  

value volunt2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  
	  
value spirituality2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  

value vote2018c
      1= 'yes'
	  2= 'no'
      3= 'not a register voter';
run;

proc freq data=wellbeing_p;
tables race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 elders2018c
rel_attend2018_r spirituality2018_r community2018_r volunt2018_r work_hours2018c work_home2018d flsa_type2018 ;
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
title "check categorical covariates";
run;

proc means N NMISS MEAN STD MIN MAX data=wellbeing_p;
var distracted2019_r jobsatis2019 /*w_productive2019*/
    WELL_BEING_eH2018 emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018
    WELL_BEING_eH2018_em WELL_BEING_eH2018_ph WELL_BEING_eH2018_sc WELL_BEING_eH2018_ch WELL_BEING_eH2018_fn WELL_BEING_eH2018_ps
    lifesat2018 happy72018 expect_good2018 menthlth2018 r_depressed2018 r_anxiety_surv2018 control2018
	understand2018 meaning2018  purpose2018  purpose_und2018  worthylife2018  purs_imp2018
	relation_sat2018  people_und2018 r_lonely2018  relation_content2018  people_help2018  connected2018  trust_comm2018
	doing_good2018 doing_right2018 respect2018 happy_later2018 difficulties2018 give_up2018 strength_help2018
	expens_diff2018 rw_food_hous_exp2018 savings_suff2018 fin_freedom2018 fin_future2018 r_debt2018
	physhlth2018 no_illness2018 no_rout_sick2018  health_noprev2018 r_pain2018  hlth_future2018  hlth_maint2018 
    avg_p502018 num_health_cond2017 w_meaning2018 w_recognized2018 w_team2018 
    distracted2018_r jobsatis2018 /*w_productive2018*/;
title "check continuous variables before standardizing";
run;

data wellbeing;
set wellbeing_p;

proc standard data=wellbeing mean=0 std=1 out=wellbeing;
var distracted2019_r jobsatis2019 /*w_productive2019*/
    WELL_BEING_eH2018 emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018
    WELL_BEING_eH2018_em WELL_BEING_eH2018_ph WELL_BEING_eH2018_sc WELL_BEING_eH2018_ch WELL_BEING_eH2018_fn WELL_BEING_eH2018_ps
    lifesat2018 happy72018 expect_good2018 menthlth2018 r_depressed2018 r_anxiety_surv2018 control2018
	understand2018 meaning2018  purpose2018  purpose_und2018  worthylife2018  purs_imp2018
	relation_sat2018  people_und2018 r_lonely2018  relation_content2018  people_help2018  connected2018  trust_comm2018
	doing_good2018 doing_right2018 respect2018 happy_later2018 difficulties2018 give_up2018 strength_help2018
	expens_diff2018 rw_food_hous_exp2018 savings_suff2018 fin_freedom2018 fin_future2018 r_debt2018
	physhlth2018 no_illness2018 no_rout_sick2018  health_noprev2018 r_pain2018  hlth_future2018  hlth_maint2018 
    avg_p502018 num_health_cond2017 w_meaning2018 w_recognized2018 w_team2018  
    distracted2018 jobsatis2018 /*w_productive2018*/;
run;

proc means N NMISS MEAN STD MIN MAX data=wellbeing;
var distracted2019_r jobsatis2019 /*w_productive2019*/
    WELL_BEING_eH2018 emot_hlth_dim2_H2018 phys_hlth_dim_H2018 social_WB_H2018 char_str_H2018 financ_WB2_H2018 purpose_dim2_H2018
    WELL_BEING_eH2018_em WELL_BEING_eH2018_ph WELL_BEING_eH2018_sc WELL_BEING_eH2018_ch WELL_BEING_eH2018_fn WELL_BEING_eH2018_ps
    lifesat2018 happy72018 expect_good2018 menthlth2018 r_depressed2018 r_anxiety_surv2018 control2018
	understand2018 meaning2018  purpose2018  purpose_und2018  worthylife2018  purs_imp2018
	relation_sat2018  people_und2018 r_lonely2018  relation_content2018  people_help2018  connected2018  trust_comm2018
	doing_good2018 doing_right2018 respect2018 happy_later2018 difficulties2018 give_up2018 strength_help2018
	expens_diff2018 rw_food_hous_exp2018 savings_suff2018 fin_freedom2018 fin_future2018 r_debt2018
	physhlth2018 no_illness2018 no_rout_sick2018  health_noprev2018 r_pain2018  hlth_future2018  hlth_maint2018 
    avg_p502018 num_health_cond2017 w_meaning2018 w_recognized2018 w_team2018 
    distracted2018_r jobsatis2018 /*w_productive2018*/;
title 'Check distribution of continuous variables after standardization'; 
run;









